package com.baizhi.controller;

import com.baizhi.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("manager")
public class ManagerController {
    private ManagerService managerService;
    @Autowired
    public void setManagerService(ManagerService managerService) {
        this.managerService = managerService;
    }
    @RequestMapping("login2")
    @ResponseBody
    public Map login(String validatecode, String username, String password, HttpSession session){
        Map map = new HashMap();
        System.out.println("收参：username="+username);
        System.out.println("收参：validatecode="+validatecode);
        String realCode = (String) session.getAttribute("validatecode");
        if(realCode!=null&&realCode.equals(validatecode)){
            boolean login = managerService.login(username, password);
            if(login){
                System.out.println("验证成功");
                session.setAttribute("login",username);
                map.put("login2",true);
            }else{
                map.put("login2",false);
            }
        }else {
            map.put("login2",false);
        }
        return map;
    }
}
